routes = [{
    path: '/',
    url: './index.html',
  },
  {
    path: '/history/', //历史页面
    //url: './pages/history.html',
    async: function (routeTo, routeFrom, resolve, reject) {
      // Router instance
      var router = this;
      // App instance
      var app = router.app;
      // Show Preloader
      app.preloader.show();

      var userid = app.data.person.userid;

      app.request({
        async: true,
        url: URL_HEADER + 'loadTempHumiDevice',
        dataType: 'json',
        timeout: timeout,
        success: function (data, status, xhr) {
          // Hide Preloader
          app.preloader.hide();
          var array = [];
          data.forEach(function (element) {
            //console.info(element);
            var temp = null;
            var humi = null;
            var readdate = null;
            if (element.data.length === 0) {} else if (element.data.length === 1) {
              readdate = element.data[0].readdate;
              temp = element.data[0].value + "℃";
            } else if (element.data.length === 2) {
              readdate = element.data[0].readdate;
              temp = element.data[0].value + "℃";
              humi = element.data[1].value + "%RH";
            }

            array.push({
              meterid: element.rid,
              metercode: element.metercode,
              metername: element.metername,
              readdate: readdate,
              temp: temp,
              humi: humi
            });
          });
          // Resolve route to load page
          //console.info(array);
          resolve({
            componentUrl: './pages/history.html',
          }, {
            context: {
              fLastData: array,
            }
          });
        },
        error: function (xhr, status) {
          //出错
          // Hide Preloader
          app.preloader.hide();
        }
      });
    }
  },
  {
    path: '/realtime/', //实时页面
    async: function (routeTo, routeFrom, resolve, reject) {
      // Router instance
      var router = this;
      // App instance
      var app = router.app;
      // Show Preloader
      app.preloader.show();

      app.request({
        async: true,
        url: URL_HEADER + 'loadTempHumiDevice',
        dataType: 'json',
        timeout: timeout,
        success: function (data, status, xhr) {
          // Hide Preloader
          app.preloader.hide();
          var array = [];
          data.forEach(function (element) {
            //console.info(element);
            var temp = null;
            var humi = null;
            var readdate = null;
            if (element.data.length === 0) {} else if (element.data.length === 1) {
              readdate = element.data[0].readdate;
              temp = element.data[0].value + "℃";
            } else if (element.data.length === 2) {
              readdate = element.data[0].readdate;
              temp = element.data[0].value + "℃";
              humi = element.data[1].value + "%RH";
            }

            array.push({
              meterid: element.rid,
              metercode: element.metercode,
              metername: element.metername,
              readdate: readdate,
              temp: temp,
              humi: humi
            });
          });
          // Resolve route to load page
          //console.info(array);
          resolve({
            componentUrl: './pages/realtime.html',
          }, {
            context: {
              fLastData: array,
            }
          });
        },
        error: function (xhr, status) {
          //出错
          // Hide Preloader
          app.preloader.hide();
        }
      });

    }
  },
  {
    path: '/history_detail/:meterid/:metercode/:metername/',
    componentUrl: './pages/history_detail.html'
  },
  {
    path: '/realtime_detail/:meterid/:metercode/:metername/',
    componentUrl: './pages/realtime_detail.html'
  },
  {
    path: '/query/', //数据查询
    async: function (routeTo, routeFrom, resolve, reject) {
      // Router instance
      var router = this;
      // App instance
      var app = router.app;
      // Show Preloader
      app.preloader.show();

      app.request({
        async: true,
        url: URL_HEADER + 'loadTempHumiDevice',
        dataType: 'json',
        timeout: timeout,
        success: function (data, status, xhr) {
          // Hide Preloader
          app.preloader.hide();
          var array = [];
          data.forEach(function (element) {
            //console.info(element);
            var temp = null;
            var humi = null;
            var readdate = null;
            if (element.data.length === 0) {} else if (element.data.length === 1) {
              readdate = element.data[0].readdate;
              temp = element.data[0].value + "℃";
            } else if (element.data.length === 2) {
              readdate = element.data[0].readdate;
              temp = element.data[0].value + "℃";
              humi = element.data[1].value + "%RH";
            }

            array.push({
              meterid: element.rid,
              metercode: element.metercode,
              metername: element.metername,
              readdate: readdate,
              temp: temp,
              humi: humi
            });
          });
          // Resolve route to load page
          //console.info(array);
          resolve({
            componentUrl: './pages/query.html',
          }, {
            context: {
              fLastData: array,
            }
          });
        },
        error: function (xhr, status) {
          //出错
          // Hide Preloader
          app.preloader.hide();
        }
      });

    }
  },
  {
    path: '/query_result/:metercode/:metername/:history/:start/:end/', //数据查询
    componentUrl: './pages/query_result.html'
  },
  {
    path: '/person/', //我
    componentUrl: './pages/person.html',
  },


  //-----------------------------------------------------------------------------
  {
    path: '/about/',
    url: './pages/about.html',
  },
  {
    path: '/product/:id/',
    componentUrl: './pages/product.html',
  },
  // Page Loaders & Router
  {
    path: '/page-loader-template7/:user/:userId/:posts/:postId/',
    templateUrl: './pages/page-loader-template7.html',
  },
  {
    path: '/page-loader-component/:user/:userId/:posts/:postId/',
    componentUrl: './pages/page-loader-component.html',
  },
  {
    path: '/request-and-load/user/:userId/',
    async: function (routeTo, routeFrom, resolve, reject) {
      // Router instance
      var router = this;

      // App instance
      var app = router.app;

      // Show Preloader
      app.preloader.show();

      // User ID from request
      var userId = routeTo.params.userId;

      // Simulate Ajax Request
      setTimeout(function () {
        // We got user data from request
        var user = {
          firstName: 'Vladimir',
          lastName: 'Kharlampidi',
          about: 'Hello, i am creator of Framework7! Hope you like it!',
          links: [{
              title: 'Framework7 Website',
              url: 'http://framework7.io',
            },
            {
              title: 'Framework7 Forum',
              url: 'http://forum.framework7.io',
            },
          ]
        };
        // Hide Preloader
        app.preloader.hide();

        // Resolve route to load page
        resolve({
          componentUrl: './pages/request-and-load.html',
        }, {
          context: {
            user: user,
          }
        });
      }, 1000);
    },
  },
  // Default route (404 page). MUST BE THE LAST
  {
    path: '(.*)',
    url: './pages/404.html',
  },
];